<?php
    $url = new Url(); 
    $forder_upload = "video";  
    $link_avatar = Yii::app()->params["urlImages"] . "upload_avatar_video.php?forder_upload=".$forder_upload;    
    $link_url = Yii::app()->params["urlImages"] . "upload_base.php?forder_upload=".$forder_upload;      
    $arr_status = LoadConfig::$status;
    $file_path = Common::getImage($data["file"], "video", $data["create_date"]);
?>
<link rel="stylesheet" href="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/css/swfupload.css" type="text/css" />
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.queue.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/fileprogress.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/handlers.js"></script>
<script type="text/javascript">
    var i = 0;
    var j = 0;
    window.onload = function() {
        var configUploadData = {
            flash_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/js/swfupload.swf",
            create_date:'<?php echo $data["create_date"];?>',
            button_image_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/images/buttonUpload.png",
            upload_url: "<?php echo $link_avatar;?>", 
            file_types: "*.jpg;*.jpeg;*.png;*.gif", 
            file_upload_limit : 20, 
            file_queue_limit : 1, 
            debug : false
        }
        
        var configUploadData3gp = {
            flash_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/js/swfupload.swf",
            create_date:'<?php echo $data["create_date"];?>',
            button_image_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/images/buttonUpload.png",
            upload_url: "<?php echo $link_url;?>", 
            file_types: "*.3gp;", 
            file_upload_limit : 20, 
            file_queue_limit : 1, 
            debug : false
        }
        
        var configUploadDataMp4 = {
            flash_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/js/swfupload.swf",
            create_date:'<?php echo $data["create_date"];?>',
            button_image_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/images/buttonUpload.png",
            upload_url: "<?php echo $link_url;?>", 
            file_types: "*.mp4;", 
            file_upload_limit : 20, 
            file_queue_limit : 1, 
            debug : false
        }
        configUpload(configUploadData); 
        configUpload3gp(configUploadData3gp);   
        configUploadMp4(configUploadDataMp4);
    }; 
    function uploadResponse(serverData){  
        try {
            $("#txtFileName").val(""); 
            var response = $.parseJSON(serverData); // eval( "(" + serverData + ")" );      
            if(response.code==404){
                alert(response.message);return false;
            }  
            var filename = response.filename;    
            var path = response.path;
            var message = response.message;
            var code = response.code;
            var extension = response.extension;
            var filesize = response.filesize;
            $("#picture").val(filename);
            $("#show_pic").html('<img src="<?php echo Yii::app()->params["urlImages"].$forder_upload.'/';?>'+path +'/'+ filename +'" class="img-100" alt="pic">')
        } catch (e) {

        };
    }
    
    function uploadResponse3gp(serverData){  
        try {
            $("#txtFileName_3gp").val(""); 

            var response = $.parseJSON(serverData);      
            if(response.code == 404){
                alert(response.message);
                return false;
            }  
            var filename = response.filename;    
            var path = response.path;
            var message = response.message;
            var code = response.code;
            var extension = response.extension;
            var filesize = response.filesize;  
            $("#file_3gp").val(filename);
            var link_video = '<?php echo Yii::app()->params["urlImages"] . $forder_upload . '/';?>' + path + '/' + filename + '';
            $("#show_file_3gp").html('Tên file: <strong>' + link_video + '</strong>&gt;&gt;<a target="_blank" href="<?php echo $url->createUrl("video/show")?>?link='+link_video+'">Xem thử</a>');              
        } catch (e) {

        };
    }
    
    function uploadResponseMp4(serverData){  
        try {
            $("#txtFileName_mp4").val(""); 

            var response = $.parseJSON(serverData);      
            if(response.code == 404){
                alert(response.message);
                return false;
            }  
            var filename = response.filename;    
            var path = response.path;
            var message = response.message;
            var code = response.code;
            var extension = response.extension;
            var filesize = response.filesize;  
            $("#file_mp4").val(filename);
            var link_video = '<?php echo Yii::app()->params["urlImages"] . $forder_upload . '/';?>' + path + '/' + filename + '';
            $("#show_file_mp4").html('Tên file: <strong>' + link_video + '</strong>&gt;&gt;<a target="_blank" href="<?php echo $url->createUrl("video/show")?>?link='+link_video+'">Xem thử</a>');              
        } catch (e) {

        };
    }
    
    function ajaxUpdateVideo(){
        var id = '<?php echo $data["id"]?>';
        var title_video = $("#title_video").val();
        var title_sms = $("#title_sms").val();
        var categoryId = $("#categoryId").val();
        var picture = $("#picture").val();
        var introtext = $("#introtext").val();
        var file_3gp = $("#file_3gp").val();
        var file_mp4 = $("#file_mp4").val();
        var duration = $("#duration").val();
        var position = $("#position").val();
        var status = $("#status").val();
        var tag = $("#tag").val();
        var strUrl = "<?=$url->createUrl("video/ajaxUpdateVideo") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                title_video:title_video,
                title_sms:title_sms,
                categoryId:categoryId,
                picture:picture,
                introtext:introtext,
                file_3gp:file_3gp,
                file_mp4:file_mp4,
                duration:duration,
                position:position,
                status:status,
                tag:tag,
                id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    history.go(-1);
                }else{
                    $("#show_error").html(msg); 
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }          
        });
    }
</script>
<div class="main clearfix">
    <div class="box clearfix bottom30">
        <div class="col-570"> 
            <ul class="form1">
                <li class="clearfix"><label><strong>Tên video </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:360px" value="<?php echo $data["title"]?>" id="title_video"> 
                    </div>
                </li>
                <li class="clearfix"><label><strong>Tiêu đề tin nhắn </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:360px" value="<?php echo $data["title_sms"]?>" id="title_sms" maxlength="40"> 
                    </div>
                </li>
                <li class="clearfix"><label><strong>Danh mục </strong>:</label>
                    <div class="filltext">
                        <select id="categoryId" style="width: 200px;">
                            <?php foreach($data_cat as $key=>$value){?>
                                <option value="<?php echo $key;?>" <?php echo $key == $data["categoryId"] ? 'selected="selected"':''?>><?php echo $value;?></option>
                                <?php }?>
                        </select>
                    </div>
                </li>
                <li class="clearfix"><label><strong>Thời lượng </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:360px" value="<?php echo $data["duration"];?>" id="duration" maxlength="40"> 
                    </div>
                </li>
                <li class="clearfix"><label><strong>Ảnh minh họa </strong>:</label>
                    <div class="filltext">
                        <p>
                            <input type="hidden" id="txtFileName" readonly="readonly"/>
                            <input type="text" id="urlFile" style="border:1px solid #DFDFDF; width: 200px;">                            
                            <span id="spanButtonPlaceHolder"></span>
                        </p>
                        <p><i>Định dạng file: *.jpg;*.jpeg;*.png;*.gif(Dung lượng ko được quá 2 MB)</i></p>
                        <br/>
                        <div class="fieldset flash" id="fsUploadProgress">
                            <span class="legend">File upload</span>
                        </div>

                        <input type="hidden" id="picture" value="<?php echo $data["picture"];?>"/>
                        <p id="show_pic"><img class="img-100" src="<?php echo Common::getImage($data["picture"],"video",$data["create_date"])?>"/></p>
                    </div>
                </li>
                <li class="clearfix"><label><strong>Tóm tắt</strong>:</label>
                    <div class="filltext">
                        <textarea cols="5" rows="5" style="width:570px; height:120px" id="introtext"><?php echo $data["introtext"];?></textarea>
                    </div>
                </li>
                <li class="clearfix"><label><strong>File 3GP</strong>:</label>
                    <div class="filltext">
                        <p>
                            <input type="hidden" id="txtFileName_3gp" readonly="readonly"/>
                            <input type="text" id="urlFile_3gp" style="border:1px solid #DFDFDF; width: 200px;">                            
                            <span id="spanButtonPlaceHolder_3gp"></span>
                        </p> 
                        <p><i>(Dung lượng ko được quá 8 MB)</i></p>
                        <br/>
                        <div class="fieldset flash" id="fsUploadProgress_3gp">
                            <span class="legend">File upload</span>
                        </div>
                        <input type="hidden" id="file_3gp" value="<?php echo $data["file"]?>"/>                        
                        <p id="show_file_3gp">Tên File: <strong><?php echo Common::getImage($data["file"], "video", $data["create_date"])?></strong>&gt;&gt;<a target="_blank" href="<?php echo $url->createUrl("video/show")?>?link=<?php echo Common::getImage($data["file"], "video", $data["create_date"])?>">Xem thử</a></p>  
                    </div>
                </li>
                <li class="clearfix"><label><strong>File Mp4</strong>:</label>
                    <div class="filltext">
                        <p>
                            <input type="hidden" id="txtFileName_mp4" readonly="readonly"/>
                            <input type="text" id="urlFile_mp4" style="border:1px solid #DFDFDF; width: 200px;">                            
                            <span id="spanButtonPlaceHolder_mp4"></span>
                        </p>                         
                        <p><i>(Dung lượng ko được quá 8 MB)</i></p>
                        <br/>
                        <div class="fieldset flash" id="fsUploadProgress_mp4">
                            <span class="legend">File upload</span>
                        </div>
                        <input type="hidden" id="file_mp4"  value="<?php echo $data["file_mp4"]?>"/>                        
                        <p id="show_file_mp4">Tên File: <strong><?php echo Common::getImage($data["file_mp4"], "video", $data["create_date"])?></strong>&gt;&gt;<a target="_blank" href="<?php echo $url->createUrl("video/show")?>?link=<?php echo Common::getImage($data["file_mp4"], "video", $data["create_date"])?>">Xem thử</a></p>  
                    </div>
                </li>
                
                <li class="clearfix"><label><strong>Trạng thái</strong>:</label>
                    <div class="filltext">
                        <select style="width:203px;" id="status">
                            <?php foreach($arr_status as $key=>$value){?>
                                <option value="<?php echo $key;?>" <?php echo $key == $data["status"] ? 'selected="selected"':''?>><?php echo $value?></option>
                                <?php }?>
                        </select>
                    </div>
                </li>
                <li class="clearfix"><label><strong>Vị trí</strong>:</label>
                    <div class="filltext">
                        <input type="text" id="position" style="width: 360px;" value="<?php echo $data["position"];?>"/>
                    </div>
                </li>
                <li class="clearfix"><label><strong>Tag</strong>:</label>
                    <div class="filltext">
                        <p><input type="text" id="tag" value="<?php echo $data["tag_name"]?>" style="border:1px solid #DFDFDF; width: 200px;"></p>
                        <p><i>(VD: lý tông thụy;hotgirl - cách nhau bằng dấu ;)</i></p>
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input id="button_save" onclick="ajaxUpdateVideo();" type="button" value=" Sửa " class="btn-bigblue"> 
                        &nbsp;
                    <input onclick="history.go(-1)" type="button" value=" Quay lại " class="btn-bigblue">
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext" style="color: red;" id="show_error"></div>
                </li>
            </ul>
        </div>
        <div class="col5">&nbsp;</div>
        <div class="col-570">
            <div class="box">
                <ul class="form">
                    <li class="clearfix"><label>&nbsp;</label>
                        <div class="filltext">
                            <p id="mediaplayer">
                                <script type="text/javascript">
                                //document.write(setHtmlVideo('<?php echo $file_path;?>',400,300));
                                </script>
                            </p>  
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>